
/***************************************************************************
 *   sakcab 
 *                                                                         *
 *   Copyright (C) 2010 by kuerant                                         *
 *                         <kuerant@gmail.com>                             *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This library is distributed in the hope that it will be usefull, but  *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      *
 *   Library General Public License for more details.                      *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; if not, write to the Free Software   *
 *   Foundation, Inc., 59 Temple Place - Suite 330, Boston,                *
 *   MA 02111-1307, USA                                                    *
 ***************************************************************************/

#ifndef	__KC_SAKCAB_CSTORE_HPP_2010__
#define	__KC_SAKCAB_CSTORE_HPP_2010__

#include <map>
#include <vector>
#include <string>

#include <boost/thread/mutex.hpp>

#include <db_cxx.h>


#include "store.hpp"
#include "aucab.hpp"


namespace	sakcab	{


struct	KyotoConfig
{
public	:
	std::vector< std::string >	cabs;
	std::vector< std::string >	table_cabs;

public	:
	KyotoConfig( const char* ini_filename, const char* ini_section );

private :
	int		parseConfig( const char* ini_filename, const char* ini_section );
};	//// class KyotoConfig


///////////////////////////////////////////////////////////////////////
//  class KyotoStore
//

class	KyotoStore
		:	public Store
{
	typedef int32_t   	cid_type;
	typedef	Aucab		cab_type;
	typedef	Aucab*		cab_ptr;

public  :
	KyotoStore( const char* ini_filename, const char* ini_section );

    virtual ~KyotoStore(); 

public  :

    virtual int     insert( const std::string& kpin,
                            const std::string& key, 
                            const std::string& data );

    virtual int     insertAppend( const std::string& kpin,
                            const std::string& key, 
                            const std::string& data );

    virtual int     insertIgnore( const std::string& kpin,
                            const std::string& key, 
                            const std::string& data );


    virtual int     find( const std::string& kpin,
                          const std::string& key, 
                               std::string& buf  );

    virtual int     find( const std::string& kpin,
                          const std::string& key, 
                                std::vector< std::string >& all_data,
								u_int32_t  limit = 0 );


    virtual int     erase( const std::string& kpin,
                           const std::string& key );

public  :

    virtual int     insert( const std::string& table,
                            const std::string& kpin,    
                            const std::string& key,    
                            const std::string& data );

    virtual int     insertAppend( const std::string& table,
                            const std::string& kpin,    
                            const std::string& key,    
                            const std::string& data );

    virtual int     insertIgnore( const std::string& table,
                            const std::string& kpin,    
                            const std::string& key,    
                            const std::string& data );

    virtual int     find( const std::string& table,
                          const std::string& kpin,    
                          const std::string& key, 
                               std::string& buf );

    virtual int     find( const std::string& table,
                          const std::string& kpin,    
                          const std::string& key, 
                                std::vector< std::string >& all_data,
                                u_int32_t   limit = 0 );

    virtual int     erase( const std::string& table,
                           const std::string& kpin,    
                           const std::string& key );

public  :

    virtual int     insertAppend( const std::vector< std::string >& kpin,
                                  const std::vector< std::string >& key,    
                                  const std::vector< std::string >& data );

    virtual int     insertAppend( const std::vector< std::string >& table,
                                  const std::vector< std::string >& kpin,    
                                  const std::vector< std::string >& key,    
                                  const std::vector< std::string >& data );

public	:

	virtual int		slim ( void );

private	:
	
	cid_type	getCID( const std::string& kpin );
	cab_ptr		getCabPtr( cid_type cid );

	cab_ptr		getCabPtr( const std::string& table );

private	:

	KyotoConfig	_config;

	std::vector< cab_ptr >	_cabs;
	typedef	std::map< std::string, cab_ptr >	table_cabs_type;
	table_cabs_type	_table_cabs;

};	//// class KyotoStore



}	//// namespace sakcab


#endif	// __KC_SAKCAB_CSTORE_HPP_2010__

